package com.cw.base.jeeyc.biz.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.base.jeeyc.biz.converter.DeployDictConverter;
import com.cw.base.jeeyc.biz.intf.DeployDictBiz;
import com.cw.base.jeeyc.dao.mapper.DeployDictMapper;
import com.cw.base.jeeyc.dao.model.DeployDictDo;
import com.cw.base.jeeyc.deploy.dto.DeployDictDto;

/**
 * 数据字典接口业务实现类
 *
 * @author chenw
 * @date 2019-08-26 21:21:57
 */
@Service
public class DeployDictBizImpl extends ServiceImpl<DeployDictMapper, DeployDictDo> implements DeployDictBiz {
    @Autowired
    private DeployDictMapper deployDictMapper;

    /**
     * 新增数据字典
     *
     * @param request 条件
     * @return String
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addDeployDict(DeployDictDto request) {
        if (request == null) {
            return null;
        }
        deployDictMapper.insert(DeployDictConverter.dto2Do(request));
        return request.getDictKey();
    }

    /**
     * 更新数据字典
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean modifyDeployDict(DeployDictDto request) {
        if (request == null) {
            return false;
        }
        deployDictMapper.updateById(DeployDictConverter.dto2Do(request));
        return true;
    }

    /**
     * 删除数据字典
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteDeployDict(DeployDictDto request) {
        if (request == null) {
            return false;
        }
        return deployDictMapper.deleteById(request.getDictKey()) > 0;
    }
}
